/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode cur = head;
        if(cur == null) {
            return null;
        }
        if(cur.val == val) {
            return head.next;
        }
        ListNode curNext = cur.next;
        while(curNext != null) {
            if(curNext.val == val) {
                cur.next = cur.next.next;
                break;
            }
            cur = cur.next;
            curNext = curNext.next;
        }
        return head;
    }
}